﻿
<!--
https://github.com/netnr
https://gitee.com/netnr
https://www.netnr.com
https://zme.ink
-->


<!DOCTYPE html>
<html>
<head>

    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <link rel='shortcut icon' href='/favicon.ico' type='image/x-icon' />


    <title>在线电视 脚本服务</title>

    <meta name="keywords" content="netnr NET牛人 在线电视" />
    <meta name="description" content="Script Services m3u8源播放" />

</head>
<body>
<div id='LoadingMask' style='position:fixed;top:0;left:0;bottom:0;right:0;background-color:white;z-index:19999;background-image:url('/images/loading.svg');background-repeat:no-repeat;background-position:48% 45%'></div>
<link href='https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css' rel='stylesheet'>
<link href='https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css' rel='stylesheet'>
<script src='https://cdn.jsdelivr.net/npm/jquery@3.5.0/dist/jquery.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/jzjs@2.0.2/2.0.2/jz.min.js'></script>
<link href='https://cdn.jsdelivr.net/npm/netnrnav@1.1.0/src/netnrnav.css' rel='stylesheet' />
<script src='https://cdn.jsdelivr.net/npm/netnrnav@1.1.0/src/netnrnav.js' defer async></script>

<script>
    $.ajax({
        url: '/images/icon.svg?20201228',
        dataType: 'text',
        success: function (data) {
            $('body').append('<div class="d-none">' + data + '</div>')
        }
    })
</script>

        <link href="/css/global.css?v=YuzFOH_Z7ma5bs-3HMdZQu0aPQZ1pkBqrzQ_Ri8Yh3k" rel="stylesheet" />
        <script src="/js/global.js?v=ckkNo3hER74SKnNCuouMgEfxEpEMP3phtPl9uA0_Lnc"></script>
            <!--导航-->
            <button type="button" class="MenuToggle show-in-mobile btn btn-primary ml-3 mt-3">
                <span class="fa fa-align-justify fa-2x"></span>
            </button>
            <div class="netnrnav horizontal">
                <div class="netnrnav-wrapper">
                    <ul>
                        <li><a href="https://www.netnr.com" class="siteIcon"><img src="/favicon.svg" /> 首页</a></li>
                        <li><a href="https://www.netnr.com/gist/discover" title="代码片段"><span class="fa fa-fw fa-file-code-o"></span> Gist</a></li>
                        <li><a href="https://www.netnr.com/run/discover" title="在线运行代码"><span class="fa fa-fw fa-play"></span> Run</a></li>
                        <li><a href="https://www.netnr.com/doc" title="文档管理"><span class="fa fa-fw fa-book"></span> Doc</a></li>
                        <li><a href="https://www.netnr.com/draw/discover" title="绘制"><span class="fa fa-fw fa-paint-brush"></span> Draw</a></li>
                        <li><a href="/" title="ss.js.org"><span class="fa fa-fw fa-wrench"></span> 服务</a></li>
                        <li style="background-image: radial-gradient(ellipse, white, rgb(227, 248, 240))">
                            <!--标题-->
                                <a href='javascript:location.reload(false)' title="m3u8源播放">
                                    <svg class="titleicon"><use xlink:href="#tv"></use></svg> &#x5728;&#x7EBF;&#x7535;&#x89C6;
                                </a>
                        </li>
                        <li>
                            <a class="text-muted"><span class="fa fa-fw fa-ellipsis-h"></span></a>
                            <ul>
                                <li><a target="_blank" title="码云" href="https://gitee.com/netnr"><i class="fa fa-fw fa-git"></i> Gitee <sup><i class="fa small fa-external-link"></i></sup></a></li>
                                <li><a target="_blank" title="GitHub" href="https://github.com/netnr"><i class="fa fa-fw fa-github"></i> GitHub <sup><i class="fa small fa-external-link"></i></sup></a></li>
                            </ul>
                        </li>
                    </ul>
                </div>
            </div>
        <div class="min300 mt-3">
            <div class="container-fluid">
    <div class="row">
        <div class="col-md-12 mb-1">
            <div class="mx-auto">
                <div class="input-group">
                    <div class="input-group-prepend">
                        <select class="custom-select" id="seM3u8"></select>
                    </div>
                    <input id="txtM3u8" class="form-control" placeholder="请粘贴 M3U8 播放源（http 协议播放源须允许）" />
                </div>
            </div>
        </div>
        <div class="col-md-12">
            <video id="video" controls class="mw-100"></video>
        </div>
    </div>
</div>

<script src='https://cdn.jsdelivr.net/npm/hls.js@0.13.2/dist/hls.min.js'></script>


<script>
    var vd = {
        m3u8: function () { return document.getElementById('seM3u8').value },
        video: document.getElementById('video'),

        init: function () {
            $.ajax({
                url: "/lib/m3u8/tv.txt",
                success: function (data) {
                    var ds = data.split('#EXTINF:-1'), sehtm = [];
                    $.each(ds, function () {
                        var d = this;
                        var matchm3u8 = /http(.*).m3u8/i.exec(d);
                        var namem3u8 = /,(.*)/.exec(d)

                        if (matchm3u8 && namem3u8) {
                            sehtm.push('<option value="' + matchm3u8[0] + '">' + namem3u8[1] + '</option>')
                        }
                    })

                    $('#seM3u8').html(sehtm.join(''));

                    vd.play(vd.m3u8(), 1);
                }
            })

            document.getElementById('txtM3u8').oninput = function () {
                if (this.value.toLowerCase().indexOf('.m3u8') >= 0) {
                    vd.play(this.value, 1);
                }
            }

            document.getElementById('seM3u8').onchange = function () {
                vd.play(this.value, 1);
            }

            vd.autoSize();
            window.onresize = vd.autoSize;
        },
        play(m3u8, isplay) {
            if (Hls.isSupported()) {
                var hls = new Hls();
                hls.loadSource(m3u8);
                hls.attachMedia(vd.video);
                hls.on(Hls.Events.MANIFEST_PARSED, function () {
                    isplay && vd.video.play();
                });
            }
            else if (vd.video.canPlayType('application/vnd.apple.mpegurl')) {
                vd.video.src = m3u8;
                vd.video.addEventListener('loadedmetadata', function () {
                    isplay && video.play();
                });
            } else {
                vd.video.parentNode.innerHTML = "您的浏览器不支持，请换Chrome浏览器、Firefox浏览器";
            }
        },
        autoSize: function () {
            var vh = document.documentElement.clientHeight - vd.video.getBoundingClientRect().top - 10;
            vd.video.style.maxHeight = vh + "px";
        }
    }

    vd.init();
</script>
        </div>
        <a href="javascript:ss.toTop();" class="totop" title="返回顶部">ˆ</a>
</body>
</html>
